package com.luoqy.speedy.init;

import com.luoqy.speedy.core.cache.CacheServiceImpl;
import com.luoqy.speedy.data.MySql;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lumberer
 * @date 2022/9/29 15:31
 */
@Component
public class DictData implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        CacheServiceImpl cache=new CacheServiceImpl();
        List<Map<String,Object>> listData= MySql.SELECTLIST("SELECT * FROM speedy_dict",Map.class);
        listData.stream().forEach(item->{
            List<Map<String,Object>> listData2=MySql.SELECTLIST("SELECT * FROM speedy_dict_item where pid="+item.get("id"),Map.class);
            Map<String,Object> cacheData=new HashMap<>();
            listData2.stream().forEach(item2->{
                cacheData.put(item2.get("code").toString(),item2);
            });
            cache.putCache(item.get("code").toString(),cacheData,0L);
        });
    }
}
